/**
 * 封装HTTP请求
 */
import Trao from '@tarojs/taro'

import config from '../api/config/config'

const baseURL = config.host;
const header = config.header;


function baseOptions(params, method = 'GET'){
    let {url, data} = params;

    const options = {
        url: baseURL + url,
        data: data,
        method: method,
        header: header
    }

    return Trao.request(options)
}

/**
 * GET方式请求
 * @param {请求地址} url
 * @param {请求参数} data
 * @returns
 */
function get(url, data){
    return baseOptions({
        url: url,
        data: data
    }, 'GET');
}

/**
 * POST方式请求
 * @param {请求地址} url
 * @param {请求参数} data
 * @returns
 */
function post(url, data){
    return baseOptions({
        url: url,
        data: data
    }, 'POST');
}

const service = {
    get: get,
    post: post
}

export default service;

